/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package classcreator.classfillers;

import classcreator.abstractclasses.AbstractClass;
import java.util.ArrayList;

/**
 *
 * @author Samus
 */
public class InitialData {

    private static InitialData instance = new InitialData();

    public static InitialData getInstance() {
        return instance;
    }

    private InitialData() {
    }

    public void addInitData(String packagename, AbstractClass clase) {
        clase.setAssembledClass(agregarPackage(packagename, clase.getAssembledClass()));
        if (clase.getNombreclase().equals("Controller")) {
            clase.setAssembledClass(agregarImportsController(clase.getAssembledClass()));
        } else if (clase.getNombreclase().equals("DataBaseConnFactory")) {
            clase.setAssembledClass(agregarImportsConnection(clase.getAssembledClass()));
        } else {
            clase.setAssembledClass(addImports(clase.getAssembledClass(), clase));
        }
        clase.setAssembledClass(agregarClase(clase.getInheritance(), clase.getNombreclase(), clase.getAssembledClass()));
    }

    public ArrayList<String> agregarPackage(String packagename, ArrayList<String> clase) {
        clase.add("package " + packagename + ";");
        clase.add("");
        return clase;
    }

    public ArrayList<String> agregarImports(String imports, ArrayList<String> clase) {
        clase.add("import " + imports + ";");
        return clase;
    }

    public ArrayList<String> agregarClase(String inheritance, String classname, ArrayList<String> clase) {
        String res = "public class " + classname;
        if (inheritance.isEmpty()) {
            res += "{";
        } else {
            res += " extends " + inheritance + "(";
        }
        clase.add(res);
        clase.add("");
        return clase;
    }

    public ArrayList<String> closeClass(ArrayList<String> clase) {
        clase.add("}");
        return clase;
    }

    public ArrayList<String> addImports(ArrayList<String> clase, Object o) {
        //Método para agregar imports de colección si es una clase abstracta,
        //de lo contrario, agrega imports de lectura de datos (main)
        if (o instanceof AbstractClass) {
            String aux = "java.util.List";
            agregarImports(aux, clase);
            aux = "java.util.ArrayList";
            agregarImports(aux, clase);
        } else {
            String aux = "java.util.ArrayList";
            agregarImports(aux, clase);
            aux = "java.util.Scanner";
            agregarImports(aux, clase);
        }
        clase.add("");
        return clase;
    }

    public ArrayList<String> agregarImportsController(ArrayList<String> clase) {
        String res = "import com.mysql.jdbc.Connection;";
        clase.add(res);
        res = "import com.mysql.jdbc.PreparedStatement;";
        clase.add(res);
        res = "import java.sql.SQLException;";
        clase.add(res);
        res = "import java.util.logging.Level;";
        clase.add(res);
        res = "import java.util.logging.Logger;";
        clase.add(res);
        clase.add("");
        return clase;
    }

    public ArrayList<String> agregarImportsConnection(ArrayList<String> clase) {
        String res = "import java.sql.Connection;";
        clase.add(res);
        res = "import java.sql.DriverManager;";
        clase.add(res);
        res = "import java.util.logging.Level;";
        clase.add(res);
        res = "import java.util.logging.Logger;";
        clase.add(res);
        clase.add("");
        return clase;
    }
}
